@CLASS
appManager

@USE
pf/web/pfSiteManager.p
pf/types/pfString.p

hlpFormater.p

@BASE
pfSiteManager

@create[aOptions]
## aOptions.options
  ^cleanMethodArgument[]
  ^BASE:create[$aOptions]
  
  $_options[$aOptions.options]
  ^cleanMethodArgument[_options]

  $_core[$aOptions.core]
  $_formater[^hlpFormater::create[]]

  ^TEMPLET.assign[now;^date::now[]]
  ^TEMPLET.assign[formater;$_formater]
  ^TEMPLET.assign[auth;$AUTH]
  
  ^TEMPLET.assign[cssPrefix;/css]
  ^TEMPLET.assign[jsPrefix;/js]
  ^TEMPLET.assign[imagePrefix;/i]

  $_isDebug($aOptions.isDebug)
  ^TEMPLET.assign[isDebug]($_isDebug)

  ^assignVar[linkTo;$linkTo]

  ^assignModule[module;
    $.class[appModuleBase]
    $.file[appModuleBase.p]
  ]

@GET_core[]
  $result[$_core]  

@GET_isDebug[]
  $result($_isDebug)

@GET_title[]
  $result[$_title]

@SET_title[aValue]
  $_title[$aValue]
  ^assignVar[title;$_title]
  
@onINDEX[aRequest][lProduct]
  ^assignVar[modelResult;^core.module.test[]]
  ^render[index.pt]  
    
@assignModule[aName;aOptions][lArgs]
  $lArgs[
    $.core[$core]
    $.formater[$_formater]
    $.isDebug($_isDebug) 
  ]

  ^if(!def $aOptions.args){
    ^aOptions.add[$.args[$lArgs]]
  }{
     $aOptions.args[^aOptions.args.union[$lArgs]]
   }
  ^BASE:assignModule[$aName;$aOptions]

@onNOTFOUND[aRequest]
  $result[^pfHTTPResponseNotFound::create[]]

@onAuthSuccess[aRequest]
## Вызывается при удачной авторизации.


@onAuthFailed[aRequest]
## Вызывается при неудачной авторизации


@postAS-IS[aResponse]
  $aResponse.headers.cache-control[no-store, no-cache, must-revalidate, proxy-revalidate]
  $aResponse.headers.pragma[no-cache]                                                    
  $aResponse.cookie.[$_cartCookieName][
    $.value[$core.cart.sessionKey]
    $.expires($_cartCookieLifetime)
  ]
  $result[^BASE:postAS-IS[$aResponse]]
     
@postHTML[aResponse][lNoticesManager]
  ^assignVar[isLoginProcess;0]

  ^assignVar[dispatchResult;$aResponse.body]
  ^assignVar[isUserLogin;$AUTH.isUserLogin]
  ^assignVar[user;$AUTH.user]
  
  ^assignVar[sqlStat;$core.CSQL.stat]

  ^assignVar[title;^if(def $aResponse.title){$aResponse.title}{$title}]
  $aResponse.headers.cache-control[no-store, no-cache, must-revalidate, proxy-revalidate]
  $aResponse.headers.pragma[no-cache]                                                    

  $aResponse.cookie.[$_cartCookieName][
    $.value[$core.cart.sessionKey]
    $.expires($_cartCookieLifetime)
  ]

  ^switch[$aResponse.status]{
    ^case[404;DEFAULT]{
      ^assignVar[title;Страница не найдена (404)]
      $aResponse.body[^render[404.pt]]
    }
    ^case[200;DEFAULT]{$aResponse.body[^render[html.pt]]}
  }
  
  $result[^BASE:postHTML[$aResponse]]
  $_title[]
  